找传奇、传世资源到传世资源站!

android 对话框的使用(入门级示例)

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

from clipboard
from clipboard
from clipboard
from clipboard
from clipboard
package com.example.lxp20181212_duihua;import android.os.Bundle;import android.app.Activity;import android.app.AlertDialog;import android.app.ProgressDialog;import android.content.DialogInterface;import android.view.LayoutInflater;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;public class MainActivity extends Activity {Button btn1,btn2,btn3,btn4,btn5;AlertDialog.Builder builder1,builder2,builder3;ProgressDialog builder4;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);btn1 = (Button)findViewById(R.id.button1);btn2 = (Button)findViewById(R.id.button2);btn3 = (Button)findViewById(R.id.button3);btn4 = (Button)findViewById(R.id.button4);btn5 = (Button)findViewById(R.id.button5);btn1.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {// TODO 自动生成的方法存根builder1 = new AlertDialog.Builder(MainActivity.this);builder1.setIcon(R.drawable.ic_launcher);builder1.setTitle("这是一个确认对话框");builder1.setPositiveButton("确定", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface arg0, int arg1) {// TODO 自动生成的方法存根setTitle("你点击了对话框上的确定按钮");}});builder1.setNegativeButton("取消", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface arg0, int arg1) {// TODO 自动生成的方法存根setTitle("你点击了对话框上的取消按钮");}});builder1.show();}});btn2.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {// TODO 自动生成的方法存根builder2 = new AlertDialog.Builder(MainActivity.this);builder2.setIcon(R.drawable.ic_launcher);builder2.setTitle("这是一个详细实例对话框");builder2.setPositiveButton("确定", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface arg0, int arg1) {// TODO 自动生成的方法存根setTitle("你点击了对话框上的确定按钮");}});builder2.setNegativeButton("取消", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface arg0, int arg1) {// TODO 自动生成的方法存根setTitle("你点击了对话框上的取消按钮");}});builder2.setNeutralButton("详细", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface arg0, int arg1) {// TODO 自动生成的方法存根setTitle("你点击了对话框上的详细按钮");}});builder2.show();}});btn3.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {// TODO 自动生成的方法存根builder3 = new AlertDialog.Builder(MainActivity.this);builder3.setIcon(R.drawable.ic_launcher);LayoutInflater inflater = LayoutInflater.from(getApplicationContext());final View textEntryView = inflater.inflate(R.layout.text_entry, null);builder3.setView(textEntryView);builder3.setPositiveButton("确定", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface arg0, int arg1) {// TODO 自动生成的方法存根setTitle("你点击了对话框上的确定按钮");}});builder3.setNegativeButton("取消", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface arg0, int arg1) {// TODO 自动生成的方法存根setTitle("你点击了对话框上的取消按钮");}});builder3.show();}});btn4.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {// TODO 自动生成的方法存根builder4 = new ProgressDialog(MainActivity.this);builder4.setTitle("正在处理中");builder4.setMessage("等待.....");builder4.show();}});btn5.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {// TODO 自动生成的方法存根Toast.makeText(getApplicationContext(), "这是一个Toast按钮", Toast.LENGTH_LONG).show();}});}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复